//
//  FKOrderDetailPriceInfoCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKOrderDetailPriceInfoCell.h"
#import "FKOrder.h"

@interface FKOrderDetailPriceInfoCell ()

@property (nonatomic, weak) UILabel *goodsPriceLabel;
@property (nonatomic, weak) UILabel *freightPrice;
@property (nonatomic, weak) UILabel *freightPriceLabel;
@property (nonatomic, weak) UILabel *couponLabel;
@property (nonatomic, weak) UILabel *priceLabel;

@end

@implementation FKOrderDetailPriceInfoCell

- (void)setupSubviews
{
    [super setupSubviews];
    self.clipsToBounds = true;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *goodsPrice = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666 text:@"商品金额"];
    [self.contentView addSubview:goodsPrice];
    
    UILabel *freightPrice = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666 text:@"运费"];
    [self.contentView addSubview:freightPrice];
    self.freightPrice = freightPrice;
    
    UILabel *coupon = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666 text:@"优惠券"];
    [self.contentView addSubview:coupon];
    
    UILabel *price = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333 text:@"实付金额"];
    [self.contentView addSubview:price];
    
    UILabel *goodsPriceLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666];
    [self.contentView addSubview:goodsPriceLabel];
    self.goodsPriceLabel = goodsPriceLabel;
    
    UILabel *freightPriceLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666];
    [self.contentView addSubview:freightPriceLabel];
    self.freightPriceLabel = freightPriceLabel;
    
    UILabel *couponLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666];
    [self.contentView addSubview:couponLabel];
    self.couponLabel = couponLabel;
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkMainColor];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    CGFloat margin = fk_adjustW(6);
    CGFloat labelH = fk_adjustW(20);
    [goodsPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.top.offset(margin);
        make.height.offset(labelH);
    }];
    [freightPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(goodsPrice);
        make.top.equalTo(goodsPrice.mas_bottom);
    }];
    [price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(goodsPrice);
        make.bottom.offset(-margin);
    }];
    [coupon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(goodsPrice);
        make.bottom.equalTo(price.mas_top);
    }];
    [goodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-12);
        make.height.centerY.equalTo(goodsPrice);
    }];
    [freightPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(goodsPriceLabel);
        make.height.centerY.equalTo(freightPrice);
    }];
    [couponLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(goodsPriceLabel);
        make.height.centerY.equalTo(coupon);
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(goodsPriceLabel);
        make.height.centerY.equalTo(price);
    }];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKOrder class]]) {
        FKOrder *model = data;
        
        self.freightPrice.hidden = [model.item_type isEqualToString:@"1"];
        self.freightPriceLabel.hidden = [model.item_type isEqualToString:@"1"];
        
        self.goodsPriceLabel.text = fkFORMAT(@"￥%@", model.goods_price);
        self.freightPriceLabel.text = fkFORMAT(@"￥%@", model.freight);
        self.couponLabel.text = fkFORMAT(@"￥%@", model.discount_price);
        self.priceLabel.text = fkFORMAT(@"￥%@", model.price);
    }
    
    
}

@end
